<!DOCTYPE html>
<html lang="zh-CN">
    <head>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <meta name="robots" content="noodp" />
        <title>C&#43;&#43;面试题1 - L_B__</title><meta name="referrer" content="no-referrer">
<meta name="description" content="C&#43;&#43;面试题1"><meta property="og:title" content="C&#43;&#43;面试题1" />
<meta property="og:description" content="C&#43;&#43;面试题1" />
<meta property="og:type" content="article" />
<meta property="og:url" content="https://acking-you.github.io/posts/c&#43;&#43;%E5%9F%BA%E7%A1%80%E9%9D%A2%E8%AF%95%E9%A2%981/" /><meta property="og:image" content="https://acking-you.github.io/logo.png"/><meta property="article:section" content="posts" />
<meta property="article:published_time" content="2022-06-20T00:00:00+00:00" />
<meta property="article:modified_time" content="2022-06-20T00:00:00+00:00" />

<meta name="twitter:card" content="summary_large_image"/>
<meta name="twitter:image" content="https://acking-you.github.io/logo.png"/>

<meta name="twitter:title" content="C&#43;&#43;面试题1"/>
<meta name="twitter:description" content="C&#43;&#43;面试题1"/>
<meta name="application-name" content="FeelIt">
<meta name="apple-mobile-web-app-title" content="FeelIt"><meta name="theme-color" content="#ffffff"><meta name="msapplication-TileColor" content="#da532c"><link rel="canonical" href="https://acking-you.github.io/posts/c&#43;&#43;%E5%9F%BA%E7%A1%80%E9%9D%A2%E8%AF%95%E9%A2%981/" /><link rel="prev" href="https://acking-you.github.io/posts/%E9%9D%A2%E8%AF%95%E5%85%AB%E8%82%A1%E8%AE%A1%E7%AE%97%E6%9C%BA%E7%BD%91%E7%BB%9C1/" /><link rel="next" href="https://acking-you.github.io/posts/selectpollepoll%E6%B5%85%E6%9E%90/" /><link rel="stylesheet" href="/css/page.min.css"><link rel="stylesheet" href="/css/home.min.css"><script type="application/ld+json">
    {
        "@context": "http://schema.org",
        "@type": "BlogPosting",
        "headline": "C++面试题1",
        "inLanguage": "zh-CN",
        "mainEntityOfPage": {
            "@type": "WebPage",
            "@id": "https:\/\/acking-you.github.io\/posts\/c\u002b\u002b%E5%9F%BA%E7%A1%80%E9%9D%A2%E8%AF%95%E9%A2%981\/"
        },"genre": "posts","keywords": "C\u002b\u002b面试题1","wordcount":  6561 ,
        "url": "https:\/\/acking-you.github.io\/posts\/c\u002b\u002b%E5%9F%BA%E7%A1%80%E9%9D%A2%E8%AF%95%E9%A2%981\/","datePublished": "2022-06-20T00:00:00+00:00","dateModified": "2022-06-20T00:00:00+00:00","publisher": {
            "@type": "Organization",
            "name": "作者"},"author": {
                "@type": "Person",
                "name": "作者"
            },"description": "C++面试题1"
    }
    </script></head><body data-header-desktop="auto" data-header-mobile="auto"><script>(window.localStorage && localStorage.getItem('theme') ? localStorage.getItem('theme') === 'dark' : ('auto' === 'auto' ? window.matchMedia('(prefers-color-scheme: dark)').matches : 'auto' === 'dark')) && document.body.setAttribute('theme', 'dark');</script>

        <div id="mask"></div><div class="wrapper"><header class="desktop" id="header-desktop">
    <div class="header-wrapper">
        <div class="header-title">
            <a href="/" title="L_B__">L_B__</a>
        </div>
        <div class="menu">
            <div class="menu-inner"><a class="menu-item" href="/posts/"> 文章 </a><a class="menu-item" href="/tags/"> 标签 </a><a class="menu-item" href="/categories/"> 分类 </a><span class="menu-item delimiter"></span><span class="menu-item search" id="search-desktop">
                        <input type="text" placeholder="搜索文章标题或内容..." id="search-input-desktop">
                        <a href="#" class="search-button search-toggle" id="search-toggle-desktop" title="搜索">
                            <i class="fas fa-search fa-fw"></i>
                        </a>
                        <a href="#" class="search-button search-clear" id="search-clear-desktop" title="清空">
                            <i class="fas fa-times-circle fa-fw"></i>
                        </a>
                        <span class="search-button search-loading" id="search-loading-desktop">
                            <i class="fas fa-spinner fa-fw fa-spin"></i>
                        </span>
                    </span><a href="javascript:void(0);" class="menu-item theme-switch" title="切换主题">
                    <i class="fas fa-adjust fa-fw"></i>
                </a>
            </div>
        </div>
    </div>
</header><header class="mobile" id="header-mobile">
    <div class="header-container">
        <div class="header-wrapper">
            <div class="header-title">
                <a href="/" title="L_B__">L_B__</a>
            </div>
            <div class="menu-toggle" id="menu-toggle-mobile">
                <span></span><span></span><span></span>
            </div>
        </div>
        <div class="menu" id="menu-mobile"><div class="search-wrapper">
                    <div class="search mobile" id="search-mobile">
                        <input type="text" placeholder="搜索文章标题或内容..." id="search-input-mobile">
                        <a href="#" class="search-button search-toggle" id="search-toggle-mobile" title="搜索">
                            <i class="fas fa-search fa-fw"></i>
                        </a>
                        <a href="#" class="search-button search-clear" id="search-clear-mobile" title="清空">
                            <i class="fas fa-times-circle fa-fw"></i>
                        </a>
                        <span class="search-button search-loading" id="search-loading-mobile">
                            <i class="fas fa-spinner fa-fw fa-spin"></i>
                        </span>
                    </div>
                    <a href="#" class="search-cancel" id="search-cancel-mobile">
                        取消
                    </a>
                </div><a class="menu-item" href="/posts/" title="">文章</a><a class="menu-item" href="/tags/" title="">标签</a><a class="menu-item" href="/categories/" title="">分类</a><div class="menu-item"><a href="javascript:void(0);" class="theme-switch" title="切换主题">
                    <i class="fas fa-adjust fa-fw"></i>
                </a>
            </div></div>
    </div>
</header><div class="search-dropdown desktop">
    <div id="search-dropdown-desktop"></div>
</div>
<div class="search-dropdown mobile">
    <div id="search-dropdown-mobile"></div>
</div><main class="main">
                <div class="container"><div class="toc" id="toc-auto">
            <h2 class="toc-title">目录</h2>
            <div class="toc-content" id="toc-content-auto"></div>
        </div><article class="page single" data-toc="disable"><div class="featured-image"><img
        class="lazyload"
        src="/svg/loading.min.svg"
        data-src="https://img-blog.csdnimg.cn/img_convert/9c7b214855b7ea22ad8549a1afb50fc7.png#pic_center"
        data-srcset="https://img-blog.csdnimg.cn/img_convert/9c7b214855b7ea22ad8549a1afb50fc7.png#pic_center, https://img-blog.csdnimg.cn/img_convert/9c7b214855b7ea22ad8549a1afb50fc7.png#pic_center 1.5x, https://img-blog.csdnimg.cn/img_convert/9c7b214855b7ea22ad8549a1afb50fc7.png#pic_center 2x"
        data-sizes="auto"
        alt="https://img-blog.csdnimg.cn/img_convert/9c7b214855b7ea22ad8549a1afb50fc7.png#pic_center"
        title="C&#43;&#43;面试题1" /></div><div class="single-card" data-image="true"><h2 class="single-title animated flipInX">C&#43;&#43;面试题1</h2><div class="post-meta">
                <div class="post-meta-line"><span class="post-author"><a href="/" title="Author" rel=" author" class="author"><i class="fas fa-user-circle fa-fw"></i>作者</a></span>&nbsp;<span class="post-category">出版于  <a href="/categories/%E9%9D%A2%E8%AF%95%E7%9B%B8%E5%85%B3/"><i class="far fa-folder fa-fw"></i>面试相关</a></span></div>
                <div class="post-meta-line"><span><i class="far fa-calendar-alt fa-fw"></i>&nbsp;<time datetime="2022-06-20">2022-06-20</time></span>&nbsp;<span><i class="fas fa-pencil-alt fa-fw"></i>&nbsp;约 6561 字</span>&nbsp;
                    <span><i class="far fa-clock fa-fw"></i>&nbsp;预计阅读 14 分钟</span>&nbsp;</div>
            </div>
            
            <hr><div class="details toc" id="toc-static"  data-kept="">
                    <div class="details-summary toc-title">
                        <span>目录</span>
                        <span><i class="details-icon fas fa-angle-right"></i></span>
                    </div>
                    <div class="details-content toc-content" id="toc-content-static"><nav id="TableOfContents">
  <ul>
    <li><a href="#1-在main执行之前和之后执行的代码可能是什么">1、 在main执行之前和之后执行的代码可能是什么？</a></li>
    <li><a href="#2结构体内存对齐问题">2、结构体内存对齐问题？</a></li>
    <li><a href="#3指针和引用的区别">3、指针和引用的区别</a></li>
    <li><a href="#4在传递函数参数时什么时候该使用指针什么时候该使用引用呢">4、在传递函数参数时，什么时候该使用指针，什么时候该使用引用呢？</a></li>
    <li><a href="#5堆和栈的区别">5、堆和栈的区别</a></li>
    <li><a href="#6你觉得堆快一点还是栈快一点">6、你觉得堆快一点还是栈快一点？</a></li>
    <li><a href="#7区别以下指针类型">7、区别以下指针类型？</a></li>
    <li><a href="#8new--delete-与-malloc--free的异同">8、new / delete 与 malloc / free的异同</a></li>
    <li><a href="#9new和delete是如何实现的">9、new和delete是如何实现的？</a></li>
    <li><a href="#10malloc和new的区别">10、malloc和new的区别？</a></li>
    <li><a href="#11既然有了mallocfreec中为什么还需要newdelete呢直接用mallocfree不好吗">11、既然有了malloc/free，C++中为什么还需要new/delete呢？直接用malloc/free不好吗？</a></li>
    <li><a href="#12被free回收的内存是立即返还给操作系统吗">12、被free回收的内存是立即返还给操作系统吗？</a></li>
    <li><a href="#13宏定义和函数有何区别">13、宏定义和函数有何区别？</a></li>
    <li><a href="#14宏定义和typedef区别">14、宏定义和typedef区别？</a></li>
    <li><a href="#15变量声明和定义区别">15、变量声明和定义区别？</a></li>
    <li><a href="#16strlen和sizeof区别">16、strlen和sizeof区别？</a>
      <ul>
        <li><a href="#162补充题一个指针占多少字节">16.2、（补充题）一个指针占多少字节？</a></li>
      </ul>
    </li>
    <li><a href="#17常量指针和指针常量区别">17、常量指针和指针常量区别？</a></li>
    <li><a href="#18a和a有什么区别">18、a和&amp;a有什么区别？</a></li>
    <li><a href="#19c和python的区别">19、C++和Python的区别</a></li>
    <li><a href="#20c和c语言的区别">20、C++和C语言的区别</a></li>
  </ul>
</nav></div>
                </div><div class="content" id="content"><h2 id="1-在main执行之前和之后执行的代码可能是什么">1、 在main执行之前和之后执行的代码可能是什么？</h2>
<p><strong>main函数执行之前</strong>，主要就是初始化系统相关资源：</p>
<ul>
<li>设置栈指针</li>
<li>初始化静态<code>static</code>变量和<code>global</code>全局变量，即<code>.data</code>段的内容</li>
<li>将未初始化部分的全局变量赋初值：数值型<code>short</code>，<code>int</code>，<code>long</code>等为<code>0</code>，<code>bool</code>为<code>FALSE</code>，指针为<code>NULL</code>等等，即<code>.bss</code>段的内容</li>
<li>全局对象初始化，在<code>main</code>之前调用构造函数，这是可能会执行前的一些代码</li>
<li>将main函数的参数<code>argc</code>，<code>argv</code>等传递给<code>main</code>函数，然后才真正运行<code>main</code>函数</li>
<li><code>__attribute__((constructor))</code>这是gnu C里面的东西，可修饰函数，控制它在main函数之前执行，它不跨平台。</li>
</ul>
<p><strong>main函数执行之后</strong>：</p>
<ul>
<li>全局对象的析构函数会在main函数之后执行；</li>
<li>可以用 <strong><code>atexit</code></strong> 注册一个函数，它会在main 之后执行;（跨平台，是标准库里的东西</li>
<li><code>__attribute__((destructor))</code>同上面的construct，只不过是在main函数执行后。</li>
</ul>
<h2 id="2结构体内存对齐问题">2、结构体内存对齐问题？</h2>
<ul>
<li>结构体内成员按照声明顺序存储，第一个成员地址和整个结构体地址相同。</li>
<li>未特殊说明时，按结构体中size最大的成员对齐（若有double成员，按8字节对齐。）</li>
</ul>
<p>c++11以后引入两个关键字 <a href="https://zh.cppreference.com/w/cpp/language/alignas" target="_blank" rel="noopener noreffer">alignas (opens new window)</a>与 <a href="https://zh.cppreference.com/w/cpp/language/alignof" target="_blank" rel="noopener noreffer">alignof (opens new window)</a>。其中<code>alignof</code>可以计算出类型的对齐方式，<code>alignas</code>可以指定结构体的对齐方式。</p>
<p>但是<code>alignas</code>在某些情况下是不能使用的，具体见下面的例子:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-cpp" data-lang="cpp"><span class="c1">// alignas 生效的情况
</span><span class="c1"></span>
<span class="k">struct</span> <span class="nc">Info</span> <span class="p">{</span>
  <span class="kt">uint8_t</span> <span class="n">a</span><span class="p">;</span>
  <span class="kt">uint16_t</span> <span class="n">b</span><span class="p">;</span>
  <span class="kt">uint8_t</span> <span class="n">c</span><span class="p">;</span>
<span class="p">};</span>

<span class="n">std</span><span class="o">::</span><span class="n">cout</span> <span class="o">&lt;&lt;</span> <span class="k">sizeof</span><span class="p">(</span><span class="n">Info</span><span class="p">)</span> <span class="o">&lt;&lt;</span> <span class="n">std</span><span class="o">::</span><span class="n">endl</span><span class="p">;</span>   <span class="c1">// 6  2 + 2 + 2
</span><span class="c1"></span><span class="n">std</span><span class="o">::</span><span class="n">cout</span> <span class="o">&lt;&lt;</span> <span class="k">alignof</span><span class="p">(</span><span class="n">Info</span><span class="p">)</span> <span class="o">&lt;&lt;</span> <span class="n">std</span><span class="o">::</span><span class="n">endl</span><span class="p">;</span>  <span class="c1">// 2
</span><span class="c1"></span>
<span class="k">struct</span> <span class="nf">alignas</span><span class="p">(</span><span class="mi">4</span><span class="p">)</span> <span class="n">Info2</span> <span class="p">{</span>
  <span class="kt">uint8_t</span> <span class="n">a</span><span class="p">;</span>
  <span class="kt">uint16_t</span> <span class="n">b</span><span class="p">;</span>
  <span class="kt">uint8_t</span> <span class="n">c</span><span class="p">;</span>
<span class="p">};</span>

<span class="n">std</span><span class="o">::</span><span class="n">cout</span> <span class="o">&lt;&lt;</span> <span class="k">sizeof</span><span class="p">(</span><span class="n">Info2</span><span class="p">)</span> <span class="o">&lt;&lt;</span> <span class="n">std</span><span class="o">::</span><span class="n">endl</span><span class="p">;</span>   <span class="c1">// 8  4 + 4
</span><span class="c1"></span><span class="n">std</span><span class="o">::</span><span class="n">cout</span> <span class="o">&lt;&lt;</span> <span class="k">alignof</span><span class="p">(</span><span class="n">Info2</span><span class="p">)</span> <span class="o">&lt;&lt;</span> <span class="n">std</span><span class="o">::</span><span class="n">endl</span><span class="p">;</span>  <span class="c1">// 4
</span></code></pre></div><p><code>alignas</code>将内存对齐调整为4个字节。所以<code>sizeof(Info2)</code>的值变为了8。</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-cpp" data-lang="cpp"><span class="c1">// alignas 失效的情况
</span><span class="c1"></span>
<span class="k">struct</span> <span class="nc">Info</span> <span class="p">{</span>
  <span class="kt">uint8_t</span> <span class="n">a</span><span class="p">;</span>
  <span class="kt">uint32_t</span> <span class="n">b</span><span class="p">;</span>
  <span class="kt">uint8_t</span> <span class="n">c</span><span class="p">;</span>
<span class="p">};</span>

<span class="n">std</span><span class="o">::</span><span class="n">cout</span> <span class="o">&lt;&lt;</span> <span class="k">sizeof</span><span class="p">(</span><span class="n">Info</span><span class="p">)</span> <span class="o">&lt;&lt;</span> <span class="n">std</span><span class="o">::</span><span class="n">endl</span><span class="p">;</span>   <span class="c1">// 12  4 + 4 + 4
</span><span class="c1"></span><span class="n">std</span><span class="o">::</span><span class="n">cout</span> <span class="o">&lt;&lt;</span> <span class="k">alignof</span><span class="p">(</span><span class="n">Info</span><span class="p">)</span> <span class="o">&lt;&lt;</span> <span class="n">std</span><span class="o">::</span><span class="n">endl</span><span class="p">;</span>  <span class="c1">// 4
</span><span class="c1"></span>
<span class="k">struct</span> <span class="nf">alignas</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span> <span class="n">Info2</span> <span class="p">{</span>
  <span class="kt">uint8_t</span> <span class="n">a</span><span class="p">;</span>
  <span class="kt">uint32_t</span> <span class="n">b</span><span class="p">;</span>
  <span class="kt">uint8_t</span> <span class="n">c</span><span class="p">;</span>
<span class="p">};</span>

<span class="n">std</span><span class="o">::</span><span class="n">cout</span> <span class="o">&lt;&lt;</span> <span class="k">sizeof</span><span class="p">(</span><span class="n">Info2</span><span class="p">)</span> <span class="o">&lt;&lt;</span> <span class="n">std</span><span class="o">::</span><span class="n">endl</span><span class="p">;</span>   <span class="c1">// 12  4 + 4 + 4
</span><span class="c1"></span><span class="n">std</span><span class="o">::</span><span class="n">cout</span> <span class="o">&lt;&lt;</span> <span class="k">alignof</span><span class="p">(</span><span class="n">Info2</span><span class="p">)</span> <span class="o">&lt;&lt;</span> <span class="n">std</span><span class="o">::</span><span class="n">endl</span><span class="p">;</span>  <span class="c1">// 4
</span></code></pre></div><p>若<code>alignas</code>小于自然对齐的最小单位，则被忽略。</p>
<ul>
<li>
<p>如果想使用单字节对齐的方式，使用<code>alignas</code>是无效的。应该使用<code>#pragma pack(push,1)</code>或者使用<code>__attribute__((packed))</code>。</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-cpp" data-lang="cpp"><span class="cp">#if defined(__GNUC__) || defined(__GNUG__)
</span><span class="cp"></span>  <span class="cp">#define ONEBYTE_ALIGN __attribute__((packed))
</span><span class="cp">#elif defined(_MSC_VER)
</span><span class="cp"></span>  <span class="cp">#define ONEBYTE_ALIGN
</span><span class="cp"></span>  <span class="cp">#pragma pack(push,1)
</span><span class="cp">#endif
</span><span class="cp"></span>
<span class="k">struct</span> <span class="nc">Info</span> <span class="p">{</span>
  <span class="kt">uint8_t</span> <span class="n">a</span><span class="p">;</span>
  <span class="kt">uint32_t</span> <span class="n">b</span><span class="p">;</span>
  <span class="kt">uint8_t</span> <span class="n">c</span><span class="p">;</span>
<span class="p">}</span> <span class="n">ONEBYTE_ALIGN</span><span class="p">;</span>

<span class="cp">#if defined(__GNUC__) || defined(__GNUG__)
</span><span class="cp"></span>  <span class="cp">#undef ONEBYTE_ALIGN
</span><span class="cp">#elif defined(_MSC_VER)
</span><span class="cp"></span>  <span class="cp">#pragma pack(pop)
</span><span class="cp"></span>  <span class="cp">#undef ONEBYTE_ALIGN
</span><span class="cp">#endif
</span><span class="cp"></span>
<span class="n">std</span><span class="o">::</span><span class="n">cout</span> <span class="o">&lt;&lt;</span> <span class="k">sizeof</span><span class="p">(</span><span class="n">Info</span><span class="p">)</span> <span class="o">&lt;&lt;</span> <span class="n">std</span><span class="o">::</span><span class="n">endl</span><span class="p">;</span>   <span class="c1">// 6 1 + 4 + 1
</span><span class="c1"></span><span class="n">std</span><span class="o">::</span><span class="n">cout</span> <span class="o">&lt;&lt;</span> <span class="k">alignof</span><span class="p">(</span><span class="n">Info</span><span class="p">)</span> <span class="o">&lt;&lt;</span> <span class="n">std</span><span class="o">::</span><span class="n">endl</span><span class="p">;</span>  <span class="c1">// 6
</span></code></pre></div></li>
<li>
<p>确定结构体中每个元素大小可以通过下面这种方法:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-cpp" data-lang="cpp"><span class="cp">#if defined(__GNUC__) || defined(__GNUG__)
</span><span class="cp"></span>  <span class="cp">#define ONEBYTE_ALIGN __attribute__((packed))
</span><span class="cp">#elif defined(_MSC_VER)
</span><span class="cp"></span>  <span class="cp">#define ONEBYTE_ALIGN
</span><span class="cp"></span>  <span class="cp">#pragma pack(push,1)
</span><span class="cp">#endif
</span><span class="cp"></span>
<span class="cm">/**
</span><span class="cm">* 0 1   3     6   8 9            15
</span><span class="cm">* +-+---+-----+---+-+-------------+
</span><span class="cm">* | |   |     |   | |             |
</span><span class="cm">* |a| b |  c  | d |e|     pad     |
</span><span class="cm">* | |   |     |   | |             |
</span><span class="cm">* +-+---+-----+---+-+-------------+
</span><span class="cm">*/</span>
<span class="k">struct</span> <span class="nc">Info</span> <span class="p">{</span>
  <span class="kt">uint16_t</span> <span class="nl">a</span> <span class="p">:</span> <span class="mi">1</span><span class="p">;</span>
  <span class="kt">uint16_t</span> <span class="nl">b</span> <span class="p">:</span> <span class="mi">2</span><span class="p">;</span>
  <span class="kt">uint16_t</span> <span class="nl">c</span> <span class="p">:</span> <span class="mi">3</span><span class="p">;</span>
  <span class="kt">uint16_t</span> <span class="nl">d</span> <span class="p">:</span> <span class="mi">2</span><span class="p">;</span>
  <span class="kt">uint16_t</span> <span class="nl">e</span> <span class="p">:</span> <span class="mi">1</span><span class="p">;</span>
  <span class="kt">uint16_t</span> <span class="nl">pad</span> <span class="p">:</span> <span class="mi">7</span><span class="p">;</span>
<span class="p">}</span> <span class="n">ONEBYTE_ALIGN</span><span class="p">;</span>

<span class="cp">#if defined(__GNUC__) || defined(__GNUG__)
</span><span class="cp"></span>  <span class="cp">#undef ONEBYTE_ALIGN
</span><span class="cp">#elif defined(_MSC_VER)
</span><span class="cp"></span>  <span class="cp">#pragma pack(pop)
</span><span class="cp"></span>  <span class="cp">#undef ONEBYTE_ALIGN
</span><span class="cp">#endif
</span><span class="cp"></span>
<span class="n">std</span><span class="o">::</span><span class="n">cout</span> <span class="o">&lt;&lt;</span> <span class="k">sizeof</span><span class="p">(</span><span class="n">Info</span><span class="p">)</span> <span class="o">&lt;&lt;</span> <span class="n">std</span><span class="o">::</span><span class="n">endl</span><span class="p">;</span>   <span class="c1">// 2
</span><span class="c1"></span><span class="n">std</span><span class="o">::</span><span class="n">cout</span> <span class="o">&lt;&lt;</span> <span class="k">alignof</span><span class="p">(</span><span class="n">Info</span><span class="p">)</span> <span class="o">&lt;&lt;</span> <span class="n">std</span><span class="o">::</span><span class="n">endl</span><span class="p">;</span>  <span class="c1">// 1
</span></code></pre></div><p>这种处理方式是<code>alignas</code>处理不了的。</p>
</li>
</ul>
<h2 id="3指针和引用的区别">3、指针和引用的区别</h2>
<ul>
<li>指针是一个变量，存储的是一个地址，引用跟原来的变量实质上是同一个东西，是原变量的别名</li>
<li>指针可以有多级，引用只有一级</li>
<li>指针可以为空，引用不能为NULL且在定义时必须初始化</li>
<li>指针在初始化后可以改变指向，而引用在初始化之后不可再改变</li>
<li>sizeof指针得到的是本指针的大小，sizeof引用得到的是引用所指向变量的大小</li>
<li>当把指针作为参数进行传递时，也是将实参的一个拷贝传递给形参，两者指向的地址相同，但不是同一个变量，在函数中改变这个变量的指向不影响实参，而引用却可以。</li>
<li>引用本质是一个指针，同样会占4字节内存；指针是具体变量，需要占用存储空间（，具体情况还要具体分析）。</li>
<li>引用在声明时必须初始化为另一变量，一旦出现必须为typename refname &amp;varname形式；指针声明和定义可以分开，可以先只声明指针变量而不初始化，等用到时再指向具体变量。</li>
<li>引用一旦初始化之后就不可以再改变（变量可以被引用为多次，但引用只能作为一个变量引用）；指针变量可以重新指向别的变量。</li>
<li>不存在指向空值的引用，必须有具体实体；但是存在指向空值的指针。</li>
</ul>
<p>参考代码：</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-cpp" data-lang="cpp"><span class="kt">void</span> <span class="nf">test</span><span class="p">(</span><span class="kt">int</span> <span class="o">*</span><span class="n">p</span><span class="p">)</span>
<span class="p">{</span>
　　<span class="kt">int</span> <span class="n">a</span><span class="o">=</span><span class="mi">1</span><span class="p">;</span>
　　<span class="n">p</span><span class="o">=&amp;</span><span class="n">a</span><span class="p">;</span>
　　<span class="n">cout</span><span class="o">&lt;&lt;</span><span class="n">p</span><span class="o">&lt;&lt;</span><span class="s">&#34; &#34;</span><span class="o">&lt;&lt;*</span><span class="n">p</span><span class="o">&lt;&lt;</span><span class="n">endl</span><span class="p">;</span>
<span class="p">}</span>

<span class="kt">int</span> <span class="nf">main</span><span class="p">(</span><span class="kt">void</span><span class="p">)</span>
<span class="p">{</span>
    <span class="kt">int</span> <span class="o">*</span><span class="n">p</span><span class="o">=</span><span class="nb">NULL</span><span class="p">;</span>
    <span class="n">test</span><span class="p">(</span><span class="n">p</span><span class="p">);</span>
    <span class="k">if</span><span class="p">(</span><span class="n">p</span><span class="o">==</span><span class="nb">NULL</span><span class="p">)</span>
    <span class="n">cout</span><span class="o">&lt;&lt;</span><span class="s">&#34;指针p为NULL&#34;</span><span class="o">&lt;&lt;</span><span class="n">endl</span><span class="p">;</span>
    <span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
<span class="p">}</span>
<span class="c1">//运行结果为：
</span><span class="c1">//0x22ff44 1
</span><span class="c1">//指针p为NULL
</span><span class="c1"></span>

<span class="kt">void</span> <span class="nf">testPTR</span><span class="p">(</span><span class="kt">int</span><span class="o">*</span> <span class="n">p</span><span class="p">)</span> <span class="p">{</span>
	<span class="kt">int</span> <span class="n">a</span> <span class="o">=</span> <span class="mi">12</span><span class="p">;</span>
	<span class="n">p</span> <span class="o">=</span> <span class="o">&amp;</span><span class="n">a</span><span class="p">;</span>

<span class="p">}</span>

<span class="kt">void</span> <span class="nf">testREFF</span><span class="p">(</span><span class="kt">int</span><span class="o">&amp;</span> <span class="n">p</span><span class="p">)</span> <span class="p">{</span>
	<span class="kt">int</span> <span class="n">a</span> <span class="o">=</span> <span class="mi">12</span><span class="p">;</span>
	<span class="n">p</span> <span class="o">=</span> <span class="n">a</span><span class="p">;</span>

<span class="p">}</span>
<span class="kt">void</span> <span class="nf">main</span><span class="p">()</span>
<span class="p">{</span>
	<span class="kt">int</span> <span class="n">a</span> <span class="o">=</span> <span class="mi">10</span><span class="p">;</span>
	<span class="kt">int</span><span class="o">*</span> <span class="n">b</span> <span class="o">=</span> <span class="o">&amp;</span><span class="n">a</span><span class="p">;</span>
	<span class="n">testPTR</span><span class="p">(</span><span class="n">b</span><span class="p">);</span><span class="c1">//改变指针指向，但是没改变指针的所指的内容
</span><span class="c1"></span>	<span class="n">cout</span> <span class="o">&lt;&lt;</span> <span class="n">a</span> <span class="o">&lt;&lt;</span> <span class="n">endl</span><span class="p">;</span><span class="c1">// 10
</span><span class="c1"></span>	<span class="n">cout</span> <span class="o">&lt;&lt;</span> <span class="o">*</span><span class="n">b</span> <span class="o">&lt;&lt;</span> <span class="n">endl</span><span class="p">;</span><span class="c1">// 10
</span><span class="c1"></span>
	<span class="n">a</span> <span class="o">=</span> <span class="mi">10</span><span class="p">;</span>
	<span class="n">testREFF</span><span class="p">(</span><span class="n">a</span><span class="p">);</span>
	<span class="n">cout</span> <span class="o">&lt;&lt;</span> <span class="n">a</span> <span class="o">&lt;&lt;</span> <span class="n">endl</span><span class="p">;</span><span class="c1">//12
</span><span class="c1"></span><span class="p">}</span>   
</code></pre></div><p>在编译器看来, int a = 10; int &amp;b = a; 等价于 int * const b = &amp;a; 而 b = 20; 等价于 *b = 20; 自动转换为指针和自动解引用.</p>
<h2 id="4在传递函数参数时什么时候该使用指针什么时候该使用引用呢">4、在传递函数参数时，什么时候该使用指针，什么时候该使用引用呢？</h2>
<ul>
<li>需要返回函数内局部变量的内存的时候用指针。使用指针传参需要开辟内存，用完要记得释放指针，不然会内存泄漏。而返回局部变量的引用是没有意义的</li>
<li>对栈空间大小比较敏感（比如递归）的时候使用引用。使用引用传递不需要创建临时变量，开销要更小</li>
<li>类对象作为参数传递的时候使用引用，这是C++类对象传递的标准方式</li>
</ul>
<h2 id="5堆和栈的区别">5、堆和栈的区别</h2>
<ul>
<li>申请方式不同。
<ul>
<li>栈由系统自动分配。</li>
</ul>
</li>
<li>堆是自己申请和释放的。</li>
<li>申请大小限制不同。
<ul>
<li>栈顶和栈底是之前预设好的，栈是向栈底扩展，大小固定，可以通过ulimit -a查看，由ulimit -s修改。</li>
<li>堆向高地址扩展，是不连续的内存区域，大小可以灵活调整。</li>
</ul>
</li>
<li>申请效率不同。
<ul>
<li>栈由系统分配，速度快，不会有碎片。</li>
<li>堆由程序员分配，速度慢，且会有碎片。</li>
</ul>
</li>
</ul>
<p>栈空间默认是4M, 堆区一般是 1G - 4G</p>
<table>
<thead>
<tr>
<th style="text-align:left"></th>
<th>堆</th>
<th>栈</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align:left"><strong>管理方式</strong></td>
<td>堆中资源由程序员控制（容易产生memory leak）</td>
<td>栈资源由编译器自动管理，无需手工控制</td>
</tr>
<tr>
<td style="text-align:left"><strong>内存管理机制</strong></td>
<td>系统有一个记录空闲内存地址的链表，当系统收到程序申请时，遍历该链表，寻找第一个空间大于申请空间的堆结点，删 除空闲结点链表中的该结点，并将该结点空间分配给程序（大多数系统会在这块内存空间首地址记录本次分配的大小，这样delete才能正确释放本内存空间，另外系统会将多余的部分重新放入空闲链表中）</td>
<td>只要栈的剩余空间大于所申请空间，系统为程序提供内存，否则报异常提示栈溢出。（这一块理解一下链表和队列的区别，不连续空间和连续空间的区别，应该就比较好理解这两种机制的区别了）</td>
</tr>
<tr>
<td style="text-align:left"><strong>空间大小</strong></td>
<td>堆是不连续的内存区域（因为系统是用链表来存储空闲内存地址，自然不是连续的），堆大小受限于计算机系统中有效的虚拟内存（32bit 系统理论上是4G），所以堆的空间比较灵活，比较大</td>
<td>栈是一块连续的内存区域，大小是操作系统预定好的，windows下栈大小是2M（也有是1M，在 编译时确定，VC中可设置）</td>
</tr>
<tr>
<td style="text-align:left"><strong>碎片问题</strong></td>
<td>对于堆，频繁的new/delete会造成大量碎片，使程序效率降低</td>
<td>对于栈，它是有点类似于数据结构上的一个先进后出的栈，进出一一对应，不会产生碎片。（看到这里我突然明白了为什么面试官在问我堆和栈的区别之前先问了我栈和队列的区别）</td>
</tr>
<tr>
<td style="text-align:left"><strong>生长方向</strong></td>
<td>堆向上，向高地址方向增长。</td>
<td>栈向下，向低地址方向增长。</td>
</tr>
<tr>
<td style="text-align:left"><strong>分配方式</strong></td>
<td>堆都是动态分配（没有静态分配的堆）</td>
<td>栈有静态分配和动态分配，静态分配由编译器完成（如局部变量分配），动态分配由alloca函数分配，但栈的动态分配的资源由编译器进行释放，无需程序员实现。</td>
</tr>
<tr>
<td style="text-align:left"><strong>分配效率</strong></td>
<td>堆由C/C++函数库提供，机制很复杂。所以堆的效率比栈低很多。</td>
<td>栈是其系统提供的数据结构，计算机在底层对栈提供支持，分配专门 寄存器存放栈地址，栈操作有专门指令。</td>
</tr>
</tbody>
</table>
<p><strong>形象的比喻</strong></p>
<p>栈就像我们去饭馆里吃饭，只管点菜（发出申请）、付钱、和吃（使用），吃饱了就走，不必理会切菜、洗菜等准备工作和洗碗、刷锅等扫尾工作，他的好处是快捷，但是自由度小。</p>
<p>堆就象是自己动手做喜欢吃的菜肴，比较麻烦，但是比较符合自己的口味，而且自由度大。</p>
<h2 id="6你觉得堆快一点还是栈快一点">6、你觉得堆快一点还是栈快一点？</h2>
<p>毫无疑问是栈快一点。</p>
<p>因为操作系统会在底层对栈提供支持，会分配专门的寄存器存放栈的地址，栈的入栈出栈操作也十分简单，并且有专门的指令执行，所以栈的效率比较高也比较快。</p>
<p>而堆的操作是由C/C++函数库提供的，在分配堆内存的时候需要一定的算法寻找合适大小的内存。并且获取堆的内容需要两次访问，第一次访问指针，第二次根据指针保存的地址访问内存，因此堆比较慢。</p>
<h2 id="7区别以下指针类型">7、区别以下指针类型？</h2>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-cpp" data-lang="cpp"><span class="kt">int</span> <span class="o">*</span><span class="n">p</span><span class="p">[</span><span class="mi">10</span><span class="p">]</span>
<span class="kt">int</span> <span class="p">(</span><span class="o">*</span><span class="n">p</span><span class="p">)[</span><span class="mi">10</span><span class="p">]</span>
<span class="kt">int</span> <span class="o">*</span><span class="n">p</span><span class="p">(</span><span class="kt">int</span><span class="p">)</span>
<span class="kt">int</span> <span class="p">(</span><span class="o">*</span><span class="n">p</span><span class="p">)(</span><span class="kt">int</span><span class="p">)</span> 
</code></pre></div><ul>
<li>int *p[10]表示指针数组，强调数组概念，是一个数组变量，数组大小为10，数组内每个元素都是指向int类型的指针变量。</li>
<li>int (*p)[10]表示数组指针，强调是指针，只有一个变量，是指针类型，不过指向的是一个int类型的数组，这个数组大小是10。</li>
<li>int *p(int)是函数声明，函数名是p，参数是int类型的，返回值是int *类型的。</li>
<li>int (*p)(int)是函数指针，强调是指针，该指针指向的函数具有int类型参数，并且返回值是int类型的。</li>
</ul>
<h2 id="8new--delete-与-malloc--free的异同">8、new / delete 与 malloc / free的异同</h2>
<p><strong>相同点</strong></p>
<ul>
<li>都可用于内存的动态申请和释放</li>
</ul>
<p><strong>不同点</strong></p>
<ul>
<li>前者是C++运算符，后者是C/C++语言标准库函数</li>
<li>new自动计算要分配的空间大小，malloc需要手工计算</li>
<li>new是类型安全的，malloc不是。例如：</li>
</ul>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-cpp" data-lang="cpp"><span class="kt">int</span> <span class="o">*</span><span class="n">p</span> <span class="o">=</span> <span class="k">new</span> <span class="kt">float</span><span class="p">[</span><span class="mi">2</span><span class="p">];</span> <span class="c1">//编译错误
</span><span class="c1"></span><span class="kt">int</span> <span class="o">*</span><span class="n">p</span> <span class="o">=</span> <span class="p">(</span><span class="kt">int</span><span class="o">*</span><span class="p">)</span><span class="n">malloc</span><span class="p">(</span><span class="mi">2</span> <span class="o">*</span> <span class="k">sizeof</span><span class="p">(</span><span class="kt">double</span><span class="p">));</span><span class="c1">//编译无错误
</span></code></pre></div><ul>
<li>new调用名为<strong>operator new</strong>的标准库函数分配足够空间并调用相关对象的构造函数，delete对指针所指对象运行适当的析构函数；然后通过调用名为<strong>operator delete</strong>的标准库函数释放该对象所用内存。后者均没有相关调用</li>
<li>后者需要库文件支持，前者不用</li>
<li>new是封装了malloc，直接free不会报错，但是这只是释放内存，而不会析构对象</li>
</ul>
<h2 id="9new和delete是如何实现的">9、new和delete是如何实现的？</h2>
<ul>
<li>new的实现过程是：首先调用名为<strong>operator new</strong>的标准库函数，分配足够大的原始为类型化的内存，以保存指定类型的一个对象；接下来运行该类型的一个构造函数，用指定初始化构造对象；最后返回指向新分配并构造后的的对象的指针</li>
<li>delete的实现过程：对指针指向的对象运行适当的析构函数；然后通过调用名为<strong>operator delete</strong>的标准库函数释放该对象所用内存</li>
</ul>
<h2 id="10malloc和new的区别">10、malloc和new的区别？</h2>
<ul>
<li>
<p>malloc和free是标准库函数，支持覆盖；new和delete是运算符，不重载。</p>
</li>
<li>
<p>malloc仅仅分配内存空间，free仅仅回收空间，不具备调用构造函数和析构函数功能，用malloc分配空间存储类的对象存在风险；new和delete除了分配回收功能外，还会调用构造函数和析构函数。</p>
</li>
<li>
<p>malloc和free返回的是void类型指针（必须进行类型转换），new和delete返回的是具体类型指针。</p>
<blockquote>
<p>update1:感谢微信好友“猿六学算法”指出错误，已修正！</p>
</blockquote>
</li>
</ul>
<h2 id="11既然有了mallocfreec中为什么还需要newdelete呢直接用mallocfree不好吗">11、既然有了malloc/free，C++中为什么还需要new/delete呢？直接用malloc/free不好吗？</h2>
<ul>
<li>malloc/free和new/delete都是用来申请内存和回收内存的。</li>
<li>在对非基本数据类型的对象使用的时候，对象创建的时候还需要执行构造函数，销毁的时候要执行析构函数。而malloc/free是库函数，是已经编译的代码，所以不能把构造函数和析构函数的功能强加给malloc/free，所以new/delete是必不可少的。</li>
</ul>
<h2 id="12被free回收的内存是立即返还给操作系统吗">12、被free回收的内存是立即返还给操作系统吗？</h2>
<p>不是的，被free回收的内存会首先被ptmalloc使用双链表保存起来，当用户下一次申请内存的时候，会尝试从这些内存中寻找合适的返回。这样就避免了频繁的系统调用，占用过多的系统资源。同时ptmalloc也会尝试对小块内存进行合并，避免过多的内存碎片。</p>
<h2 id="13宏定义和函数有何区别">13、宏定义和函数有何区别？</h2>
<ul>
<li>宏在预处理阶段完成替换，之后被替换的文本参与编译，相当于直接插入了代码，运行时不存在函数调用，执行起来更快；函数调用在运行时需要跳转到具体调用函数。</li>
<li>宏定义属于在结构中插入代码，没有返回值；函数调用具有返回值。</li>
<li>宏定义参数没有类型，不进行类型检查；函数参数具有类型，需要检查类型。</li>
<li>宏定义不要在最后加分号。</li>
</ul>
<h2 id="14宏定义和typedef区别">14、宏定义和typedef区别？</h2>
<ul>
<li>宏主要用于定义常量及书写复杂的内容；typedef主要用于定义类型别名。</li>
<li>宏替换发生在编译阶段之前，属于文本插入替换；typedef是编译的一部分。</li>
<li>宏不检查类型；typedef会检查数据类型。</li>
<li>宏不是语句，不在在最后加分号；typedef是语句，要加分号标识结束。</li>
<li>注意对指针的操作，typedef char * p_char和#define p_char char *区别巨大。</li>
</ul>
<h2 id="15变量声明和定义区别">15、变量声明和定义区别？</h2>
<ul>
<li>声明仅仅是把变量的声明的位置及类型提供给编译器，并不分配内存空间；定义要在定义的地方为其分配存储空间。</li>
<li>相同变量可以在多处声明（外部变量extern），但只能在一处定义。</li>
</ul>
<h2 id="16strlen和sizeof区别">16、strlen和sizeof区别？</h2>
<ul>
<li>sizeof是运算符，并不是函数，结果在编译时得到而非运行中获得；strlen是字符处理的库函数。</li>
<li>sizeof参数可以是任何数据的类型或者数据（sizeof参数不退化）；strlen的参数只能是字符指针且结尾是'\0&rsquo;的字符串。</li>
<li>因为sizeof值在编译时确定，所以不能用来得到动态分配（运行时分配）存储空间的大小。</li>
</ul>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-cpp" data-lang="cpp">  <span class="kt">int</span> <span class="nf">main</span><span class="p">(</span><span class="kt">int</span> <span class="n">argc</span><span class="p">,</span> <span class="kt">char</span> <span class="k">const</span> <span class="o">*</span><span class="n">argv</span><span class="p">[]){</span>
      
      <span class="k">const</span> <span class="kt">char</span><span class="o">*</span> <span class="n">str</span> <span class="o">=</span> <span class="s">&#34;name&#34;</span><span class="p">;</span>

      <span class="k">sizeof</span><span class="p">(</span><span class="n">str</span><span class="p">);</span> <span class="c1">// 取的是指针str的长度，是8
</span><span class="c1"></span>      <span class="n">strlen</span><span class="p">(</span><span class="n">str</span><span class="p">);</span> <span class="c1">// 取的是这个字符串的长度，不包含结尾的 \0。大小是4
</span><span class="c1"></span>      <span class="k">return</span> <span class="mi">0</span><span class="p">;</span>
  <span class="p">}</span>
</code></pre></div><h3 id="162补充题一个指针占多少字节">16.2、（补充题）一个指针占多少字节？</h3>
<p>在16题中有提到sizeof（str）的值为8，是在64位的编译环境下的，指针的占用大小为8字节；</p>
<p>而在32位环境下，指针占用大小为4字节。</p>
<p>一个指针占内存的大小跟编译环境有关，而与机器的位数无关。</p>
<p>还有疑问的，可以自行打开Visual Studio编译器自己实验一番。</p>
<h2 id="17常量指针和指针常量区别">17、常量指针和指针常量区别？</h2>
<ul>
<li>指针常量是一个指针，读成常量的指针，指向一个只读变量，也就是后面所指明的int const 和 const int，都是一个常量，可以写作int const *p或const int *p。</li>
<li>常量指针是一个不能给改变指向的指针。指针是个常量，必须初始化，一旦初始化完成，它的值（也就是存放在指针中的地址）就不能在改变了，即不能中途改变指向，如int *const p。</li>
</ul>
<h2 id="18a和a有什么区别">18、a和&amp;a有什么区别？</h2>
<p>假设数组int a[10]; int (*p)[10] = &amp;a;其中：</p>
<ul>
<li>a是数组名，是数组首元素地址，+1表示地址值加上一个int类型的大小，如果a的值是0x00000001，加1操作后变为0x00000005。*(a + 1) = a[1]。</li>
<li>&amp;a是数组的指针，其类型为int (*)[10]（就是前面提到的数组指针），其加1时，系统会认为是数组首地址加上整个数组的偏移（10个int型变量），值为数组a尾元素后一个元素的地址。</li>
<li>若(int *)p ，此时输出 *p时，其值为a[0]的值，因为被转为int *类型，解引用时按照int类型大小来读取。</li>
</ul>
<h2 id="19c和python的区别">19、C++和Python的区别</h2>
<p>包括但不限于：</p>
<ul>
<li>Python是一种脚本语言，是解释执行的，而C++是编译语言，是需要编译后在特定平台运行的。python可以很方便的跨平台，但是效率没有C++高。</li>
<li>Python使用缩进来区分不同的代码块，C++使用花括号来区分</li>
<li>C++中需要事先定义变量的类型，而Python不需要，Python的基本数据类型只有数字，布尔值，字符串，列表，元组等等</li>
<li>Python的库函数比C++的多，调用起来很方便</li>
</ul>
<h2 id="20c和c语言的区别">20、C++和C语言的区别</h2>
<ul>
<li>C++中new和delete是对内存分配的运算符，取代了C中的malloc和free。</li>
<li>标准C++中的字符串类取代了标准C函数库头文件中的字符数组处理函数（C中没有字符串类型）。</li>
<li>C++中用来做控制态输入输出的iostream类库替代了标准C中的stdio函数库。</li>
<li>C++中的try/catch/throw异常处理机制取代了标准C中的setjmp()和longjmp()函数。</li>
<li>在C++中，允许有相同的函数名，不过它们的参数类型不能完全相同，这样这些函数就可以相互区别开来。而这在C语言中是不允许的。也就是C++可以重载，C语言不允许。</li>
<li>C++语言中，允许变量定义语句在程序中的任何地方，只要在是使用它之前就可以；而C语言中，必须要在函数开头部分。而且C++不允许重复定义变量，C语言也是做不到这一点的</li>
<li>在C++中，除了值和指针之外，新增了引用。引用型变量是其他变量的一个别名，我们可以认为他们只是名字不相同，其他都是相同的。</li>
<li>C++相对与C增加了一些关键字，如：bool、using、dynamic_cast、namespace等等</li>
</ul>
</div><div class="post-footer" id="post-footer">
    <div class="post-info"><div class="post-info-tag"><span><a href="/tags/c&#43;&#43;%E9%9D%A2%E8%AF%95%E9%A2%981/">C&#43;&#43;面试题1</a>
                </span></div><div class="post-info-line"><div class="post-info-mod">
                <span>更新于 2022-06-20</span>
            </div><div class="post-info-mod"></div>
        </div><div class="post-info-share">
            <span><a href="javascript:void(0);" title="分享到 Twitter" data-sharer="twitter" data-url="https://acking-you.github.io/posts/c&#43;&#43;%E5%9F%BA%E7%A1%80%E9%9D%A2%E8%AF%95%E9%A2%981/" data-title="C&#43;&#43;面试题1" data-hashtags="C&#43;&#43;面试题1"><i class="fab fa-twitter fa-fw"></i></a><a href="javascript:void(0);" title="分享到 Facebook" data-sharer="facebook" data-url="https://acking-you.github.io/posts/c&#43;&#43;%E5%9F%BA%E7%A1%80%E9%9D%A2%E8%AF%95%E9%A2%981/" data-hashtag="C&#43;&#43;面试题1"><i class="fab fa-facebook-square fa-fw"></i></a><a href="javascript:void(0);" title="分享到 WhatsApp" data-sharer="whatsapp" data-url="https://acking-you.github.io/posts/c&#43;&#43;%E5%9F%BA%E7%A1%80%E9%9D%A2%E8%AF%95%E9%A2%981/" data-title="C&#43;&#43;面试题1" data-web><i class="fab fa-whatsapp fa-fw"></i></a><a href="javascript:void(0);" title="分享到 Line" data-sharer="line" data-url="https://acking-you.github.io/posts/c&#43;&#43;%E5%9F%BA%E7%A1%80%E9%9D%A2%E8%AF%95%E9%A2%981/" data-title="C&#43;&#43;面试题1"><i class="fab fa-line fa-fw"></i></a><a href="javascript:void(0);" title="分享到 微博" data-sharer="weibo" data-url="https://acking-you.github.io/posts/c&#43;&#43;%E5%9F%BA%E7%A1%80%E9%9D%A2%E8%AF%95%E9%A2%981/" data-title="C&#43;&#43;面试题1" data-image="https://img-blog.csdnimg.cn/img_convert/9c7b214855b7ea22ad8549a1afb50fc7.png#pic_center"><i class="fab fa-weibo fa-fw"></i></a><a href="javascript:void(0);" title="分享到 Myspace" data-sharer="myspace" data-url="https://acking-you.github.io/posts/c&#43;&#43;%E5%9F%BA%E7%A1%80%E9%9D%A2%E8%AF%95%E9%A2%981/" data-title="C&#43;&#43;面试题1" data-description="C&#43;&#43;面试题1"><i data-svg-src="/lib/simple-icons/icons/myspace.min.svg"></i></a><a href="javascript:void(0);" title="分享到 Blogger" data-sharer="blogger" data-url="https://acking-you.github.io/posts/c&#43;&#43;%E5%9F%BA%E7%A1%80%E9%9D%A2%E8%AF%95%E9%A2%981/" data-title="C&#43;&#43;面试题1" data-description="C&#43;&#43;面试题1"><i class="fab fa-blogger fa-fw"></i></a><a href="javascript:void(0);" title="分享到 Evernote" data-sharer="evernote" data-url="https://acking-you.github.io/posts/c&#43;&#43;%E5%9F%BA%E7%A1%80%E9%9D%A2%E8%AF%95%E9%A2%981/" data-title="C&#43;&#43;面试题1"><i class="fab fa-evernote fa-fw"></i></a></span>
        </div></div><div class="post-nav"><a href="/posts/%E9%9D%A2%E8%AF%95%E5%85%AB%E8%82%A1%E8%AE%A1%E7%AE%97%E6%9C%BA%E7%BD%91%E7%BB%9C1/" class="prev" rel="prev" title="面试八股——计算机网络1"><i class="fas fa-angle-left fa-fw"></i>Previous Post</a>
            <a href="/posts/selectpollepoll%E6%B5%85%E6%9E%90/" class="next" rel="next" title="select、poll、epoll浅析">Next Post<i class="fas fa-angle-right fa-fw"></i></a></div></div>
</div></article></div>
            </main>
            <footer class="footer"><div class="footer-container"><div class="footer-line">由 <a href="https://gohugo.io/" target="_blank" rel="noopener noreffer" title="Hugo 0.86.0">Hugo</a> 强力驱动 | 主题 - <a href="https://github.com/khusika/FeelIt" target="_blank" rel="noopener noreffer" title="FeelIt 1.0.1"><i class="fas fa-hand-holding-heart fa-fw"></i> FeelIt</a>
        </div><div class="footer-line" itemscope itemtype="http://schema.org/CreativeWork"><i class="far fa-copyright fa-fw"></i><span itemprop="copyrightYear">2023</span><span class="author" itemprop="copyrightHolder">&nbsp;<a href="/"></a></span></div>
</div>
</footer>
        </div>

        <div id="fixed-buttons"><a href="#" id="back-to-top" class="fixed-button" title="回到顶部">
                <i class="fas fa-chevron-up fa-fw"></i>
            </a></div><link rel="stylesheet" href="/lib/fontawesome-free/all.min.css"><link rel="stylesheet" href="/lib/animate/animate.min.css"><link rel="stylesheet" href="/lib/katex/katex.min.css"><link rel="stylesheet" href="/lib/katex/copy-tex.min.css"><script src="/lib/autocomplete/autocomplete.min.js"></script><script src="/lib/lunr/lunr.min.js"></script><script src="/lib/lunr/lunr.stemmer.support.min.js"></script><script src="/lib/lunr/lunr.zh.min.js"></script><script src="/lib/lazysizes/lazysizes.min.js"></script><script src="/lib/clipboard/clipboard.min.js"></script><script src="/lib/sharer/sharer.min.js"></script><script src="/lib/katex/katex.min.js"></script><script src="/lib/katex/auto-render.min.js"></script><script src="/lib/katex/copy-tex.min.js"></script><script src="/lib/katex/mhchem.min.js"></script><script>window.config={"code":{"copyTitle":"复制到剪贴板","maxShownLines":200},"comment":{},"math":{"delimiters":[{"display":true,"left":"$$","right":"$$"},{"display":true,"left":"\\[","right":"\\]"},{"display":false,"left":"$","right":"$"},{"display":false,"left":"\\(","right":"\\)"}],"strict":false},"search":{"highlightTag":"em","lunrIndexURL":"/index.json","lunrLanguageCode":"zh","lunrSegmentitURL":"/lib/lunr/lunr.segmentit.js","maxResultLength":100,"noResultsFound":"没有找到结果","snippetLength":50,"type":"lunr"}};</script><script src="/js/theme.min.js"></script></body></html>
